#!/usr/bin/python3
#-*- coding:utf-8 -*-
u"""爬虫."""
import sys
import os


class ExtractMirna:
    u"""爬取人家的数据库."""

    def __init__(self):
        u"""初始化，指定附近的gff3文件，并且准备mirna的名字."""
        self.root_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
        self.gff3 = os.path.join(self.root_dir, 'scripts/hsa.gff3')
        self.mirna_names = self.extract_mirna_names()
        self.mirna_names.sort()

    def extract_mirna_names(self):
        u"""提取mirna_name."""
        names = set()
        with open(self.gff3) as f_:
            for line in f_:
                if line.startswith('chr') and 'primary' in line:
                    msg = line.split()[-1].split(';')
                    name = {key: value for key, value in [
                        x.split('=') for x in msg]}
                    names.add(name['Name'])
        return list(names)
